import { ApiItem } from '@/types/api';
import { PageQueryParamType, pageRequest, sendPostRequest, sendGetJsonRequest } from '@/utils/requestEx';

/**
 * 分页查询参条件
 * @param funcCode 可输，参数名称
 * @param funcName 可输，参数键名
 */
export interface ApiQueryType extends PageQueryParamType {
  funcCode?: string;
  funcName?: string;
  owner?: string;
  clstCode?: string;
  appCode?: string;
  roleId?: string;
}

export async function fetchAllApi(params: ApiQueryType) {
  const endPointURI = '/dev/apiscope/list';
  return pageRequest(endPointURI, params);
}

export async function addApi(params: ApiItem) {
  const endPointURI = '/dev/apiscope/add';
  return sendPostRequest(endPointURI, params);
}

export async function updateApi(params: ApiItem) {
  const endPointURI = '/dev/apiscope/update';
  return sendPostRequest(endPointURI, params);
}

export async function deleteApis(params: ApiItem) {
  const endPointURI = '/dev/apiscope/delete';
  return sendPostRequest(endPointURI, params);
}

export async function fetchApiTreeByRole(params: ApiQueryType) {
  const { roleId } = params;
  const endPointURI = `/dev/role/apiscope/tree/${roleId}`;
  return sendGetJsonRequest(endPointURI, params);
}